<?php
class ControllerDelimanNhatkyhethong extends Controller
{
	private $error = array();
   	function __construct() 
	{
		$listchek = $this->getListCheck();
		if(in_array($this->getMethod(),$listchek))
		{
			if(!$this->user->hasPermission($this->getRoute(), $this->getMethod()))
			{
				$this->response->redirect("?route=common/permission");
			}
		}
		
	 	$this->load->model("deliman/nhatkyhethong");
		$this->load->model("deliman/nhanvien");
		
   	}
	
	public function index()
	{			
		$this->getList();
	}
		
	private function getList() 
	{
		$data = $this->request->get;
		$where = "";
		if (trim($data['tungay']) != "")
		{
			$where .= " AND ngaythaotac >= '".date('Y-m-d',strtotime($data['tungay']))."'";
		}
		if (trim($data['denngay']) != "")
		{
			$where .= " AND ngaythaotac <= '".date('Y-m-d',strtotime($data['denngay']))." 24:00:00'";
		}
		if($data['nhanvienid'] != "")
		{
			$where .= " AND nhanvienid = '".$data['nhanvienid']."'";
		}
		$page = (int)$this->request->get['page'];
		if($page == 0)
		$page = 1;
		$offset = ($page-1)*20;
		$count = 20;
		$where .= " ORDER BY `ngaythaotac` DESC LIMIT ".$offset." , ".$count;
		$this->data['datas'] = $this->model_deliman_nhatkyhethong->getList($where);
		$this->data['page'] = $page;
		//echo count($this->data['datas']);
		/*//Page
		$page = $this->request->get['page'];		
		$x=$page;		
		$limit = 20;
		$total = count($this->data['datas']); 
		// work out the pager values 
		$this->data['pager']  = $this->pager->pageLayout($total, $limit, $page); 
		
		$pager  = $this->pager->getPagerData($total, $limit, $page); 
		$offset = $pager->offset; 
		$limit  = $pager->limit; 
		$page   = $pager->page;
		for($i=$offset;$i < $offset + $limit && count($rows[$i])>0;$i++)
		{
			
		}*/
		// Load ds nhan vien
		
		$this->data['danhsachnhanvien'] = $this->model_deliman_nhanvien->getList();
		
		$this->data['refres']=$_SERVER['QUERY_STRING'];
		$this->id='content';
		$this->template="deliman/nhatkyhethong_list.tpl";
		if($data['print'] == "true")
			$this->layout="layout/print";
		else
			$this->layout="layout/deliman";
		
		$this->render();
	}	
}
?>